--[[/**
-- * 
 * 吸引普攻子弹
 *
 * 这个buff是在召唤物身上
-- *
-- */]]

---@class BuffEffect5205100 : BaseBuffEffect
BuffEffect5205100 = ClientFight.CreateClass("BuffEffect5205100", ClientFight.BaseBuffEffect)
local t = BuffEffect5205100
t.BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES = "BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local times = buff.effectParams[t.BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES] or 0;
    buff.effectParams[t.BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES] = times + 1;
    local fr = parameters[3];
    fr.damage = 0;
    local skill = parameters[2];
    local skillBean = skill.skill.skillBean;
    --        if (skillBean.getF_SkillType() == 1 && skillBean.getF_BulletTpye() == 1) then
    fr.state = DamageResultTypeEnum.SHIELD;
    --        end
    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 吸引普攻子弹：" .. (times + 1));
    local master = buff.target.summonsCreater;
    if (master ~= nil and table.getn(buff.buffBean.f_BuffEffectValue) > 1) then
        local addEnergy = buff.buffBean.f_BuffEffectValue[2];
        SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
                .. buff.modelId .. " 吸引普攻子弹时额外给主人恢复能量：" .. addEnergy);
        FighterManager.addEnergy(fight, master, 0, 0, addEnergy, EnergyChangeReasonEnum.BUFF);
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end

function t:remove(fight, buff, force, ...)
    --移除时给主人加个buff
    local addBuffId = buff.buffBean.f_BuffEffectValue[1];
    local master = buff.target.summonsCreater;
    if (master == nil) then
        return ClientFight.BaseBuffEffect.remove(self, fight, buff, force, ...);
    end
    local times = buff.effectParams[t.BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES] or 0;
    if (times < 1) then
        return ClientFight.BaseBuffEffect.remove(self, fight, buff, force, ...);
    end
    local result = BuffManager.addBuff(fight, buff.skill, master, master, false, addBuffId, 1);
    local o = result[1];
    if (o ~= IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE) then
        return ClientFight.BaseBuffEffect.remove(self, fight, buff, force, ...);
    end
    local addBuff = result[2];
    addBuff.effectParams[t.BUFF_EFFECT_522100_GENERAL_ATTACK_TIMES] = times;
    return ClientFight.BaseBuffEffect.remove(self, fight, buff, force, ...);
end
t.New()